<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80" @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="业务名称" name="businessName">
            <t-input
              v-model="queryParams.businessName"
              clearable
              placeholder="请输入项目名称"
              style="width: 240px"
            />
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <t-table
      rowKey="id"
      :data="data"
      :columns="columns"
      hover
      :pagination="pagination"
      :loading="dataLoading"
    >
      <template #name="{row}">
        <div >{{ row.achievement.name }}</div>
      </template>
      <template #approveType="{row}">
        {{ row.approveType|filterByDict(dict.type.cgzh_approve_type) }}
      </template>
      <template #status="{row}">
        <t-tag  v-if="row.approveType==='1'" @click="dialog.header=row.achievement.name;dialog.objId=row.achievement.id;dialog.open_approve_list=true" class="cursor-pointer"
               :theme="handleTheme(row.thesisStatus, dict.type.achievement_status)" variant="light">
          {{ row.achievement.thesisStatus | filterByDict(dict.type.achievement_status) }}
        </t-tag>
        <t-tag  v-if="row.approveType==='2'" @click="dialog.header=row.achievement.name;dialog.objId=row.achievement.id;dialog.open_approve_list=true" class="cursor-pointer"
                :theme="handleTheme(row.treatiseStatus, dict.type.achievement_status)" variant="light">
          {{ row.achievement.treatiseStatus | filterByDict(dict.type.achievement_status) }}
        </t-tag>
        <t-tag  v-if="row.approveType==='3'" @click="dialog.header=row.achievement.name;dialog.objId=row.achievement.id;dialog.open_approve_list=true" class="cursor-pointer"
                :theme="handleTheme(row.patentStatus, dict.type.achievement_status)" variant="light">
          {{ row.achievement.patentStatus | filterByDict(dict.type.achievement_status) }}
        </t-tag>
        <t-tag  v-if="row.approveType==='4'" @click="dialog.header=row.achievement.name;dialog.objId=row.achievement.id;dialog.open_approve_list=true" class="cursor-pointer"
                :theme="handleTheme(row.softwareCopyrightStatus, dict.type.achievement_status)" variant="light">
          {{ row.achievement.softwareCopyrightStatus | filterByDict(dict.type.achievement_status) }}
        </t-tag>
        <t-tag  v-if="row.approveType==='5'" @click="dialog.header=row.achievement.name;dialog.objId=row.achievement.id;dialog.open_approve_list=true" class="cursor-pointer"
                :theme="handleTheme(row.awardsStatus, dict.type.achievement_status)" variant="light">
          {{ row.achievement.awardsStatus | filterByDict(dict.type.achievement_status) }}
        </t-tag>
        <t-tag  v-if="row.approveType==='6'" @click="dialog.header=row.achievement.name;dialog.objId=row.achievement.id;dialog.open_approve_list=true" class="cursor-pointer"
                :theme="handleTheme(row.performanceStatus, dict.type.achievement_status)" variant="light">
          {{ row.achievement.performanceStatus | filterByDict(dict.type.achievement_status) }}
        </t-tag>
      </template>

      <template #op="{row}">
        <t-button @click="dialog.row=row;dialog.open=true" size="small" variant="text" class="t-button-link">
          <t-icon name="edit-1" slot="icon"/>
          审批
        </t-button>
      </template>
    </t-table>
    <approve-info
      :visible.sync="dialog.open"
      @reload="getList()"
      :row="dialog.row"
      v-if="dialog.open">
    </approve-info>
    <approve-list :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_approve_list" v-if="dialog.open_approve_list"></approve-list>
  </div>
</template>

<script>
import ApproveList from "./components/approve-list.vue";
import ApproveInfo from "./components/approve-info.vue";

export default {
  name: "approve-my",
  dicts: ['cgzh_approve_type', 'achievement_status'],
  components:{
    ApproveList,
    ApproveInfo
  },
  data(){
    return {
      dialog:{
        row: null,
        open: false,
        open_approve_list: false
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        approveType: '',
        businessName: '',
      },
      data: [],
      columns: [
        {
          colKey: "name",
          title: "成果名称",
          align: "center",
          // ellipsis: true,
          width:220,
        },
        {
          colKey: "status",
          title: "成果状态",
          align: "center",
          // ellipsis: true,
          width:220,
        },
        {
          colKey: "businessName",
          title: "业务名称",
          align: "center",
          ellipsis: true
        },
        {
          colKey: "approveType",
          title: "审批业务类型",
          align: "center",
        },
        {
          colKey: "createTime",
          title: "创建时间",
          align: "center",
          width: 200
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 200
        },
      ],

      dataLoading: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  created() {
    this.getList()
  },
  methods:{
    getList() {
      this.dataLoading = true;
      this.$api.cgzh.approve.myApproveList(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
  }
}
</script>

<style scoped>

</style>
